﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Aim2 {
    public static class TextureHelper {
        public static Rectangle getTextureRectangle(Tuple<int, int> textureLayout, int frame, int textureWidth, int textureHeight, float scale = 1.0f) {
            int x, y, width, height;
            width = textureWidth / textureLayout.Item1;
            height = textureHeight / textureLayout.Item2;

            y = height * (frame / textureLayout.Item1);
            x = frame % textureLayout.Item1 * width;
            Rectangle ret = new Rectangle(x, y, width, height);

            if (scale != 1f) {
                ret.Width *= (int)scale;
                ret.Height *= (int)scale;
            }

            return ret;
        }

        public static Tuple<int, int> GetLayout(this String str) {
            string [] temp = str.Split('/')[1].Split('_')[0].Split('x');
            return new Tuple<int, int>(Convert.ToInt16(temp[0]), Convert.ToInt16(temp[1]));
        }
    }
}
